<template>
  <div class="outflow_view">
    <!-- 添加或修改申请采购明细对话框 -->
    <el-dialog :visible.sync="open" :title="title" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="190px" :rules="rules" style="margin-top: -20px" size="mini">
        <el-row>
          <el-col :span="12">
              <el-form-item label="品名:" label-width="130px">
                {{form.materialName}}
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="领用数量:" label-width="130px">
                {{form.occupationQuantity}}
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
              <el-form-item label="学院:" label-width="130px">
                {{getCollegeName}}
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="实验室:" label-width="130px">
                {{getLabName}}
              </el-form-item>
          </el-col>
        </el-row>
        
        <el-row>
          <el-col :span="24">
              <el-form-item label="领取时间:" label-width="130px">
                {{form.receiverTime}}
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
              <el-form-item label="领取人学(工)号:" prop="recipient1No" label-width="130px">
                {{form.receiver1No}}
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="领取人姓名:" label-width="130px">
                {{form.receiver1Name}}
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
              <el-form-item label="领取人学(工)号:" prop="recipient2No" label-width="130px">
                {{form.receiver2No}}
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="领取人姓名:" label-width="130px">
                {{form.receiver2Name}}
              </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table style="width: 100%; margin-bottom: 20px; margin-top: -15px" :data="form.deliverList">
          <el-table-column label="序号" align="center" type="index"/>
          <el-table-column label="二维码内容" align="left" prop="qrCode" :show-overflow-tooltip="true" />
          <el-table-column label="出库人" align="center" prop="createBy" />
          <el-table-column label="出库时间" align="center" prop="createTime" />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getDetails, updateDetails } from "@/api/labdanger/occupationDetail";
import { getOrgByFunctionOpt, listSecondOrgLab } from "@/api/labdata/orgnization";
export default {
  name: "AddAgentia",
  data() {
    return {
      title:'出库确认',
      open: false,
      // 表单参数
      form: {},
      //二级机构
      secondOrgList: [],
      //二级机构下的实验室
      secondOrgLabList: [],
      rules: {
      }
    };
  },
  props: {
  },
  created() {
    this.getCollege()
  },
  computed: {
    getCollegeName() {
      const org = this.secondOrgList.find(item => item.orgId == this.form.collegeId)
      return org ? org.orgName : ''
    },
    getLabName() {
      const org = this.secondOrgLabList.find(item => item.orgId == this.form.labId)
      return org ? org.orgName : ''
    }
  },
  updated() {
  },
  methods: {
    searchDetails(detailId) {
      getDetails(detailId).then(response => {
        this.form = response.data;
        this.getLabOrgs()
        //强制刷新
        this.$forceUpdate();
      })
    },
    getCollege() {
      getOrgByFunctionOpt(2).then(response => {
        this.secondOrgList = response.data;
      });
    },
    getLabOrgs() {
      listSecondOrgLab(this.form.collegeId).then(response => {
        this.secondOrgLabList = response.data;
      });
    },
    /** 新增按钮操作 */
    handleShow(row) {
      this.reset(); 
      this.searchDetails(row.occupationDetailsId)
      this.open = true;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
      };
    },
    submitForm(e) {
      this.$refs['form'].validate((valid)=> {
        if (valid) {
          
        }
      })
    }
  }
};
</script>

<style scoped lang="scss">
  /deep/  .el-button.active{
    text-decoration: underline;
    color: #0000ee;
    margin-left: 15px;
  }
  .dialog-footer {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
  }
  /deep/ .el-form-item{
    margin-bottom: 0px;
  }
</style>